import './index.css'
import '@/page/nav-side/index.js'
import RenderTemplate from '@/util/hogan/index.js'
import text from './template.js'
import {orderService} from '@/service/order-service.js'
import Pagination from '@/util/pagination/index.js'

let orderList = {
	data : {
		listParam : {
			pageNum : 1,
			pageSize : 10
		},
		simulateData : {
			container : "pagination",
			hasPreviousPage : true,
	        prePage         : 4,
	        hasNextPage     : true,
	        nextPage        : 6,
	        pageNum         : 5,
	        totalPages      : 10
		}
	},
	init : function(){
		this.loadOrderList()
		/*
		let modifySelectPage = (res) =>{
			this.data.listParam.pageNum = res.pageNum;
			console.log(res)
		}
		*/
		
	},
	// use simulateData if not please remove  this comment
	loadPagination : function(){
		let renderObject = Object.assign({},this.data.simulateData,
			{
				modifySelectPage:(res) =>{
					
					this.data.simulateData.pageNum = Number.parseInt(res)

					this.loadOrderList()
				}
			}
		)
		console.log(this.data.simulateData.pageNum)
		new Pagination().render(renderObject)
	},
	// use simulateData if not please remove  this comment
	loadOrderList : function(){
		console.log("loadOrderList")
		orderService.getOrderList(this.data.listParam, (res) => {
			
			new RenderTemplate(text,res.data).render().then((res) => {
			
				document.getElementsByClassName("order-list-con")[0].innerHTML = res+this.data.simulateData.pageNum;
				
			this.data.simulateData.prePage = this.data.simulateData.pageNum - 1 > 0 ? this.data.simulateData.pageNum -1 :0
			this.data.simulateData.nextPage = this.data.simulateData.pageNum + 1 < this.data.simulateData.totalPages ? this.data.simulateData.pageNum + 1 :this.data.simulateData.totalPages
			console.log(this.data.simulateData.prePage + ":" +this.data.simulateData.nextPage)
			this.loadPagination();	
			},() => {
				console.log("error")
			})
			
		},(errMsg) => {
			console.log("request error"+errMsg)
		})
		
	}
};

(() => {
	orderList.init()
	
})()